package com.bamboowind.dead.ttl;

import com.bamboowind.util.RabbitMqUtils;
import com.rabbitmq.client.AMQP;
import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;

/**
 * @Author cpw
 * @Date 2022/11/2 9:34
 * 生产者
 */
public class Producer {
    public static final String NORMAL_EXCHANGE = "normal_exchange";

    public static void main(String[] args) throws Exception {
        Channel channel = RabbitMqUtils.getChannel();
        // 声明交换机
        channel.exchangeDeclare(NORMAL_EXCHANGE, BuiltinExchangeType.DIRECT);
        // 设置消息的ttl时间
        AMQP.BasicProperties ttl = new AMQP.BasicProperties().builder().expiration("10000").build();

        for (int i = 1; i < 11; i++) {
            String message = "消息" + i;
            channel.basicPublish(NORMAL_EXCHANGE, "zhangsan", ttl, message.getBytes());
            System.out.println("生产者发送消息:" + message);
        }
    }
}
